
#!/bin/sh
FILE=myfvafile.ine
cp $1 $FILE
echo "Copying $1 to temporary file $FILE"
DONE="0";

VARS=`cat $FILE | egrep '[0-9]+ +[0-9]+ +r.*' | gawk '{print $2 - 1}'`
echo "The .ine file $FILE contained $VARS variables"


echo "Building lower bound template..."
cat $FILE | gawk -f testfvSYMBOLIC.gawk LOWER > tcLOWER_TEMPLATE.cplex
echo "Building upper bound template..."
cat $FILE | gawk -f testfvSYMBOLIC.gawk UPPER > tcUPPER_TEMPLATE.cplex
	
	for i in $(seq 1 1 $VARS);
		do
		# echo "Computing min/max information for variable $i"
		rm unnamed.sol > /dev/null 2> /dev/null

		cat tcLOWER_TEMPLATE.cplex | gawk -f convert.gawk $i > tc.cplex

		# ./glpsol --cpxlp --cgr --exact tc.cplex -o blah >/dev/null
		./esolver -O -L tc.cplex > qsoptSTDOUT 2> qsoptSTDERR
		# grep 'Value' unnamed.sol
		# cp unnamed.sol "poom_${i}_LB"
		RESULTLOWER=`grep 'Value' unnamed.sol | gawk '{ print $3 }'`

		rm unnamed.sol > /dev/null 2> /dev/null 

		cat tcUPPER_TEMPLATE.cplex | gawk -f convert.gawk $i > tc.cplex

		# cat $FILE | gawk -f testfv.gawk $i UPPER > tc.cplex
		# ./glpsol --cpxlp --cgr --exact tc.cplex -o blah >/dev/null
		./esolver -O -L tc.cplex > qsoptSTDOUT 2> qsoptSTDERR
		# cp unnamed.sol "poom_${i}_UB"
		# grep 'Value' unnamed.sol

		RESULTUPPER=`grep 'Value' unnamed.sol | gawk '{ print $3 }'`

		if [ "$RESULTUPPER" = "" ];
			then
			RESULTUPPER="99999999"
			fi

		if [ "$RESULTLOWER" = "" ];
			then
			RESULTLOWER="-99999999"
			fi

		echo "x${i} : $RESULTLOWER : $RESULTUPPER";

		done

